/*
 * WaitingList.fx
 * Author: Yu Min-ting
 * Created on 2009-7-19, 12:19:56
 */

package com.sjtu.fx.user;

import com.sjtu.fx.tools.*;
import com.sjtu.fx.tools.SwingTable.*;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

public class waiting{
    public var bookName:String;
    public var availableDate:String;
    public var state:String;
}

public class MyWaitingList extends CustomNode {
    var panel:Panel;
    var list:waiting[] = bind list with inverse;
    public var selection: Integer;


    var waitingTable:SwingTable = SwingTable{
        columns: [
                    TableColumn {
                        text: "Book Name"
                    },
                    TableColumn {
                        text: "Available Date"
                    },
                    TableColumn {
                        text: "State"
                    },
                ]
        rows: bind for (u in list)
                    TableRow{
                        cells:[
                            TableCell {
                                text:bind u.bookName
                            },
                            TableCell {
                                text:bind u.availableDate
                            },
                            TableCell {
                                text: bind u.state
                            },
                        ]
                    }
        selection: bind selection with inverse

    }

    var borrow = Button {
            text: "Borrow it Now"
            action: function() {
                if(selection>=0){
                    // to do

                    delete list[selection];
                }
            }
        }
     var remove = Button {
            text: "Remove it from My List"
            action: function() {
                if(selection>=0){
                    // to do

                    delete list[selection];
                }
            }
        }

   override protected function create() : Node {

        Group{
            content:[
                 panel = Panel {
                    width:    430
                    height:   550
                    title:    " My Waiting List"
                    translateX: 0
                    translateY: 0
                },
                 VBox{
                    spacing: 25
                    translateX:32 translateY: 60
                    content:[
                        waitingTable,
                        HBox{
                            translateX:30
                            spacing:50
                            content:[borrow,remove]
                        }
                    ]

                }


            ]
        }
     }
}
